import Vue from 'vue'
import Router from 'vue-router'
Vue.use(Router)

/* Layout */
import Layout from '@/layout'
export const constantRoutes = [
  {
    path: '/',
    component: () => import('@/views/login/index'),
    hidden: true
  },

  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },
  {
    path: '/order',
    component: Layout,
    children: [
      {
        path: 'order',
        name: 'Order',
        component: () => import('@/views/order/index'),
        meta: { title: '订单管理', icon: 'el-icon-s-order' }
      }
    ]
  },
  {
    path: '/workOrder',
    component: Layout,
    children: [
      {
        path: 'workOrder',
        name: 'WorkOrder',
        component: () => import('@/views/workOrder/index'),
        meta: { title: '工单管理', icon: 'el-icon-s-promotion' }
      }
    ]
  },
  {
    path: '/allocation',
    component: Layout,
    children: [
      {
        path: 'allocation',
        name: 'Allocation',
        component: () => import('@/views/allocation/index'),
        meta: { title: '配置管理', icon: 'el-icon-s-tools' }
      }
    ]
  },
  {
    path: '/comprehensive',
    component: Layout,
    meta: { title: '综合服务管理', icon: 'el-icon-s-cooperation' },
    children: [
      {
        path: 'comprehensive',
        name: 'Comprehensive',
        component: () => import('@/views/comprehensive/index'),
        meta: { title: '综合服务', icon: '' }
      },
      {
        path: 'classify',
        name: 'Classify',
        component: () => import('@/views/comprehensive/classify'),
        meta: { title: '综合服务分类', icon: '' }
      },
    ]
  },
  {
    path: '/helpCenter',
    component: Layout,
    children: [
      {
        path: 'helpCenter',
        name: 'HelpCenter',
        component: () => import('@/views/helpCenter/index'),
        meta: { title: '帮助中心管理', icon: 'el-icon-s-comment' }
      }
    ]
  },
  {
    path: '/commonTools',
    component: Layout,
    children: [
      {
        path: 'commonTools',
        name: 'CommonTools',
        component: () => import('@/views/commonTools/index'),
        meta: { title: '常用工具管理', icon: 'el-icon-s-grid' }
      }
    ]
  },
  {
    path: '/commonFunctions',
    component: Layout,
    children: [
      {
        path: 'commonFunctions',
        name: 'CommonFunctions',
        component: () => import('@/views/commonFunctions/index'),
        meta: { title: '常用功能管理', icon: 'el-icon-s-grid' }
      }
    ]
  },
  {
    path: '/attentionList',
    component: Layout,
    children: [
      {
        path: 'attentionList',
        name: 'AttentionList',
        component: () => import('@/views/attentionList/index'),
        meta: { title: '注意事项管理', icon: 'el-icon-s-grid' }
      }
    ]
  },
  {
    path: '/company',
    component: Layout,
    children: [
      {
        path: 'company',
        name: 'Company',
        component: () => import('@/views/company/index'),
        meta: { title: '快递公司管理', icon: 'el-icon-s-grid' }
      }
    ]
  },
  {
    path: '/userManagement',
    component: Layout,
    meta: { title: '用户管理', icon: 'el-icon-user-solid' },
    children: [
      {
        path: 'userManagement',
        name: 'UserManagement',
        component: () => import('@/views/userManagement/index'),
        meta: { title: '用户管理', icon: 'el-icon-user-solid' }
      },
      {
        path: 'userRole',
        name: 'UserRole',
        component: () => import('@/views/userRole/index'),
        meta: { title: '用户角色', icon: 'el-icon-user-solid' }
      },
    ]
  },
  {
    path: '/manager',
    component: Layout,
    meta: { title: '权限管理', icon: 'el-icon-s-opportunity' },
    children: [
      {
        path: 'manager',
        name: 'Manager',
        component: () => import('@/views/manager/index'),
        meta: { title: '管理员', icon: '' }
      },
      {
        path: 'routerGroup',
        name: 'RouterGroup',
        component: () => import('@/views/routerGroup/index'),
        meta: { title: '管理员组管理', icon: '' }
      },
      {
        path: 'router',
        name: 'Router',
        component: () => import('@/views/router/index'),
        meta: { title: '路由管理', icon: '' }
      },


    ]
  },
  { path: '*', redirect: '/404', hidden: true }
]

/**
 * asyncRoutes
 * the routes that need to be dynamically loaded based on user roles
 */

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
